package com.beiming.config;

import com.beiming.common.interceptor.AuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
        @Bean
        public AuthInterceptor authInterceptor() {
            return new AuthInterceptor();
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            // 放行路径
            List<String> patterns = new ArrayList();
           // patterns.add("/login");
            //暂时不拦截
            patterns.add("/**/login");
            patterns.add("/**/logout");
            patterns.add("/**/register");
            patterns.add("/**/getOneCate");
            patterns.add("/**/getTwoCate");
            patterns.add("/images/**");
            registry.addInterceptor(authInterceptor()).addPathPatterns("/**")
                    .excludePathPatterns(patterns);
        }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // /images/**是静态映射， file:/root/images/是文件在服务器的路径
        registry.addResourceHandler("/images/**")
                .addResourceLocations("file:D:/BaiduNetdiskDownload/code/img/");
    }
}
